﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class HisNameBLL : IHisNameBLL
    {
        private static readonly IHisNameDAL dal = DataAccess.CreateHisNames();
        //private static readonly IEmployeeDAL empDAL = DataAccess.CreateEmployees();
        //private static readonly IMasNamePrefixDAL pfDAL = DataAccess.CreateMasterNamePrefixes();

        private EmployeeInfo empInfo = new EmployeeInfo();
        private MasNamePrefixInfo opfInfo = new MasNamePrefixInfo();
        private MasNamePrefixInfo npfInfo = new MasNamePrefixInfo();
        private HisNameInfo hisInfo = new HisNameInfo();

        public IList<HisNameInfo> ListHisNames(string Employee)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            hisInfo.Employee = empInfo;

            return dal.ListHisNames(hisInfo);
        }
        public IList<HisNameInfo> ListHisNameBySequence(int Sequence)
        {
            return dal.ListHisNames(new HisNameInfo(Sequence));
        }
        public DataSet LoadHisNames(Nullable<int> Sequence, Nullable<int> EmpSequence)
        {
            hisInfo.Sequence = 0;
            if (Sequence.HasValue)
                hisInfo.Sequence = (int)Sequence;
            if (EmpSequence.HasValue)
            {
                empInfo.Sequence = (int)EmpSequence;
                hisInfo.Employee = empInfo;
            }
            return dal.LoadHisNames(hisInfo);
        }
        public void Insert(string Employee, Nullable<DateTime> ChangedDate, string ChangeRefNo, string OldPrefixes
            , string OldFirstName, string OldLastName, string NewPrefixes, string NewFirstName, string NewLastName
            , string Remarks, int CreatedBy)
        {
            try
            {
                empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
                opfInfo.Sequence = OldPrefixes.Length > 0 ? Int32.Parse(OldPrefixes) : 0;
                npfInfo.Sequence = NewPrefixes.Length > 0 ? Int32.Parse(NewPrefixes) : 0;

                dal.Insert(new HisNameInfo(0, ChangedDate, ChangeRefNo, OldFirstName, OldLastName, NewFirstName
                    , NewLastName, empInfo, opfInfo, npfInfo, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Employee, Nullable<DateTime> ChangedDate, string ChangeRefNo
            , string OldPrefixes, string OldFirstName, string OldLastName, string NewPrefixes, string NewFirstName
            , string NewLastName, string Remarks, int UpdatedBy)
        {
            try
            {
                empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
                opfInfo.Sequence = OldPrefixes.Length > 0 ? Int32.Parse(OldPrefixes) : 0;
                npfInfo.Sequence = NewPrefixes.Length > 0 ? Int32.Parse(NewPrefixes) : 0;

                dal.Update(new HisNameInfo(Sequence, ChangedDate, ChangeRefNo, OldFirstName, OldLastName, NewFirstName
                    , NewLastName, empInfo, opfInfo, npfInfo, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
